#!/bin/bash

#
# Convert an image cropping it to a square
#
# ----------
# -- Args --
# ----------
# > width of the new image
# > rotation of the image 

if [ x$3 = 'xbackground' ] ; then
    FMT="${5:-png}"
    BACKGROUND="$4"
else
    FMT="${3:-png}"
    BACKGROUND="none"
fi

`dirname $0`/convertResize $1 | \
convert - \
          -bordercolor white  -border 2 \
          -bordercolor grey60 -border 1 \
          -background  none   -rotate $2 \
          -background  black  \( +clone -shadow 30x1+1+1 \) +swap \
          -background  $BACKGROUND  -flatten  $FMT:-
